$(function() {
	$("#footer").load('footer.html', function() {});

	if(window.location.search != "") {
		var aId = window.location.href.split('?')[1].split('=')[1];
		console.log(aId)
	}
	var _url = decodeURI(window.location.search)
	var condition = _url.split('condition=')[1]
//获取分类
	$.ajax({
		url: host + '/NPLAPI/GetProductCate',
		type: 'post',
		dataType: 'JSON',
		success: function(res) {
			var list = res.data
			if(res.state) {
				var html = ''
				$.each(list, function(i, item) {
					if(item.id == aId) {
						$('.case-tab-list li').eq(0).removeClass('active')
						html += `<li class="tab-name active" data-id="${item.id}">
								<a javascript: void (0)>${item.name}</a>
							</li>`
						_getList(item.id)
					} else {
						html += `<li class="tab-name" data-id="${item.id}">
								<a javascript: void (0)>${item.name}</a>
							</li>`
						_getList(item.id)
					}
				})
				$('.case-tab-list').append(html)

			}
		}
	});

	$('.case-tab-list').on('click', '.tab-name', function() {
		aId = $(this).attr('data-id')
		$(this).addClass('active').siblings('.active').removeClass('active')
		$('.onshop-list').html('')
		_getList(aId)
	})

	var _getList = function(id) {

		$.ajax({
			url: host + '/MtmlAPI/ActiveCategory',
			type: 'POST',
			dataType: 'JSON',
			data: {
				cid: cid,
				index: 1,
				size: 100,
				category: id,
				condition: condition
			},
			success: function(res) {
				if(res.state) {
					$(".lazy").lazyload({
						effect: "fadeIn",
					}).removeClass("lazy");
					var obj = res.data.list
					for(var i = 0; i < obj.length; i++) {
						var id = obj[i].IptId
						$('.onshop-list').append(
							`
            		<li>
            			<div class='lazy onshop-list-img' data-original=${obj[i].FirstImg}></div>
						<div class="onshop-list-txt">
							<div class="onshop-goods">${obj[i].title}</div>
						<div class="onshop-price">美丽价: <span>${obj[i].price}元</span></div>
						<div class="onshop-list-more"><a href="project-detail.html?IptId=${id}">查看详情</a></div>
						</div>
					</li>
            			`
						)

					}

				} else {

				}
			},
			error: function() {}
		})
	}
   
	$.ajax({
		type: "post",
		url: host + '/CMSAPI/MainInList',
		dataType: 'JSON',
		data: {
			index: 1,
			size: 4,
			categorys: 168,
			menuID: 5,
			cid: cid
		},
		success: function(res) {
			var main = res.data.list
			if(res.state) {
				var html1 = '',
					html2 = ''
				for(var i = 0; i < main.length; i++) {
					html1 += `<li data-target="#myCarousel" data-slide-to="${i}" class="cicle"></li>`
					html2 += `<div class="item">
								<div class='index-banner' style='background-image:url(${main[i].images[0].URL});'></div>
							</div>`
				}

				$('.carousel-indicators').append(html1);
				$('.carousel-inner').append(html2);
				$('.cicle:eq(0)').addClass('active');
				$('.item:eq(0)').addClass('active');
				$('.carousel').carousel({
					interval: 2500
				});
			}
		}
	});
})